import axios from "axios"
import api from './index'
// 网络请求接口列表
//  在vue3项目中 axios 关于post请求，注意文档类型
// 接口1：管理员登录
// http://localhost:4000/api/user/signin
export const singin = async (data={})=> {
    return axios.post(
        `${api.url}/api/user/signin`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}

// 接口2：验证码
// http://localhost:4000/api/verify/test
export const test = async (data={})=> {
    return axios.get(
        `${api.url}/api/verify/test`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口3: 用户列表
// http://localhost:4000/api/user/list
export const userList = async (data={})=> {
    return axios.get(`${api.url}/api/user/list`, {params: data}).then(response => response.data)
}

// 接口4：添加考试分类
// http://127.0.0.1:4000/api/exam/category_add
export const categoryAdd = async (data={})=> {
    return axios.post(
        `${api.url}/api/exam/category_add`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}

// 接口5： 获取考试分类列表
// http://127.0.0.1:4000/api/exam/category_list
export const categoryList = async (data={})=> {
    return axios.get(
        `${api.url}/api/exam/category_list`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口6： 删除考试分类
// http://127.0.0.1:4000/api/exam/category_remove
export const categoryRemove = async (data={})=> {
    return axios.get(
        `${api.url}/api/exam/category_remove`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口7：上传图片
// http://localhost:4000/api/photo/upload
export const photoUpload = async (data={})=> {
    return axios.post(
        `${api.url}/api/photo/upload`, 
         data,
         {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        }
    )
    .then(response => response.data)
}
// 接口8：删除图片
// http://localhost:4000/api/photo/delete
export const photoDelete = async (data={})=> {
    return axios.post(
        `${api.url}/api/photo/delete`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}

// 接口9：发布试卷
// http://127.0.0.1:4000/api/exam/exam_add
export const examAdd = async (data={})=> {
    return axios.post(
        `${api.url}/api/exam/exam_add`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}

// 接口10：试卷列表
// http://127.0.0.1:4000/api/exam/exam_list_all
export const examList = async (data={})=> {
    return axios.get(
        `${api.url}/api/exam/exam_list_all`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口11：删除试卷
// http://127.0.0.1:4000/api/exam/exam_remove
export const examRemove = async (data={})=> {
    return axios.get(
        `${api.url}/api/exam/exam_remove`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口12：获取试卷列表（分页）
// http://127.0.0.1:4000/api/exam/exam_items
export const examItems = async (data={})=> {
    return axios.get(
        `${api.url}/api/exam/exam_items`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口：获取账号信息
// http://localhost:4000/api/user/info
export const getAccountInfo = async (data={})=> {
    return axios.post(
        `${api.url}/api/user/info`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}


// 接口: 使用第三方API获取账号登录IP地址
export const getIpAdress = async ()=> {
    return axios.get(
        // 'https://api.ipify.org?format=json'
        // 发送请求到 ip-api.com 获取IP地址的地理位置信息
        'http://ip-api.com/json'
    )
    .then(response => response.data)
    .catch(error => {
        console.error('无法获取IP地址信息：', error);
    });
}

// 轮播图：
// 接口：新增轮播图
// http://localhost:4000/api/banner/add
export const addBanner = async (data={})=> {
    return axios.post(
        `${api.url}/api/banner/add`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}
// 接口：删除轮播图
// http://localhost:4000/api/banner/remove
export const removeBanner = async (data={})=> {
    return axios.post(
        `${api.url}/api/banner/remove`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}
// 接口：修改轮播图
// http://localhost:4000/api/banner/edit
export const editBanner = async (data={})=> {
    return axios.post(
        `${api.url}/api/banner/edit`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}

// 接口：获取轮播图列表
// http://localhost:4000/api/banner/list
export const getBannerList = async (data={})=> {
    return axios.get(
        `${api.url}/api/banner/list`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}


// 面试题：
// 接口：新增面试题主菜单
// http://127.0.0.1:4000/api/interview/category_add
export const addInterviewCategory = async (data={})=> {
    return axios.post(
        `${api.url}/api/interview/category_add`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}

// 接口：面试题主菜单列表
// http://127.0.0.1:4000/api/interview/category_list
export const listInterviewCategory = async (data={})=> {
    return axios.get(
        `${api.url}/api/interview/category_list`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口：删除面试题主菜单
// http://127.0.0.1:4000/api/interview/category_remove
export const removeInterviewCategory = async (data={})=> {
    return axios.get(
        `${api.url}/api/interview/category_remove`, 
        {
            params: data
         } 
    )
    .then(response => response.data)
    .catch(error => {
        console.error('请求失败', error);
    });
}

// 接口：新增面试题子菜单
// http://127.0.0.1:4000/api/interview/menu_add
export const addInterviewMenu = async (data={})=> {
    return axios.post(
        `${api.url}/api/interview/menu_add`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}

// 接口：面试题子主菜单列表
// http://127.0.0.1:4000/api/interview/menu_list
export const listInterviewMenu = async (data={})=> {
    return axios.get(
        `${api.url}/api/interview/menu_list`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口：删除子面试题主菜单
// http://127.0.0.1:4000/api/interview/menu_remove
export const removeInterviewMenu = async (data={})=> {
    return axios.get(
        `${api.url}/api/interview/menu_remove`, 
        {
            params: data
         } 
    )
    .then(response => response.data)
    .catch(error => {
        console.error('请求失败', error);
    });
}

// 接口：新增面试题
// http://127.0.0.1:4000/api/interview/topic_add
export const addInterviewTopic = async (data={})=> {
    return axios.post(
        `${api.url}/api/interview/topic_add`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}

// 接口：面试题列表
// http://127.0.0.1:4000/api/interview/topic_list
export const listInterviewTopic = async (data={})=> {
    return axios.get(
        `${api.url}/api/interview/topic_list`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口：删除面试题
// http://127.0.0.1:4000/api/interview/topic_remove
export const removeInterviewTopic = async (data={})=> {
    return axios.get(
        `${api.url}/api/interview/topic_remove`, 
        {
            params: data
         } 
    )
    .then(response => response.data)
    .catch(error => {
        console.error('请求失败', error);
    });
}

// 接口：面试题列表
// http://127.0.0.1:4000/api/interview/topic_list_all
export const listInterviewTopicAll = async (data={})=> {
    return axios.get(
        `${api.url}/api/interview/topic_list_all`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}


// 接口：统计各分类面试题数量
// http://127.0.0.1:4000/api/interview/topic_category_total
export const totalInterviewCategory = async (data={})=> {
    return axios.get(
        `${api.url}/api/interview/topic_category_total`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口：统计各分类试卷数量
// http://127.0.0.1:4000/api/exam/exam_category_total
export const totalExamCategory = async (data={})=> {
    return axios.get(
        `${api.url}/api/exam/exam_category_total`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}